﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.App_Code.DTO;
using Manager.App_Code.IDAL;
using Manager.App_Code.DAL;
using Manager.App_Code.REPORTS;

namespace Manager.FormAdd_Edit
{
    public partial class Frm_CheckOut : DevExpress.XtraEditors.XtraForm
    {
        public Frm_CheckOut()
        {
            InitializeComponent();
        }

     

        PhieuDangKyPhongDTO phieudkdto;

        public PhieuDangKyPhongDTO Phieudkdto
        {
            get { return phieudkdto; }
            set { phieudkdto = value; }

        }

        double tongtien;

        public double Tongtien
        {
            get { return tongtien; }
            set { tongtien = value; }
        }

        public Frm_CheckOut(PhieuDangKyPhongDTO phieudkdto1, double tongtien1)
        {
            InitializeComponent();
            phieudkdto = phieudkdto1;
            tongtien = tongtien1;
        }


        private void butThoat_Click(object sender, EventArgs e)
        {
            
            this.Close();
        }



        //frm_CheckOutMain checkoutmain;
        Int64 MaHD;
        private void Frm_CheckOut_Load(object sender, EventArgs e)
        {
            dateNgayGhiHD.Text = DateTime.Now.ToShortDateString();


            if (Phieudkdto != null)
            {
                //MessageBox.Show("Truyen dược rồi đấy " + Phieudkdto.MaKhachHang.TenKH + Tongtien.ToString());

                txtThanhTien.Text = Tongtien.ToString();
                txtMaDK.Text = Phieudkdto.MaPhieu.ToString();
                txtMaPhong.Text = Phieudkdto.MaPhong.MaPhong;
                txtHoTen.Text = Phieudkdto.MaKhachHang.TenKH;

                IHoaDonTraPhong ihoadon = new HoaDonTraPhongDAL();

                MaHD = ihoadon.GetMaxMaHoaDon() - 1;
                txtMaHoaDon.Text = MaHD.ToString();

                HoaDonTraPhongDTO hoadondto = ihoadon.GetHoaDonTraPhongByID(MaHD);
                dateNgayCheckOut.Text = hoadondto.NgayTra.ToShortDateString();

                txtHoTen.Text = Phieudkdto.MaKhachHang.TenKH;

                //IPhieuDangKy iphieudk = new PhieuDangKyDAL();
                //gridListRoom.DataSource = iphieudk.GetListPhieuDangKyPhongByID(Phieudkdto.MaPhieu, Phieudkdto.MaPhong.MaPhong);
                IPhuThuDichVu iphuthu = new PhuThuDichVuDAL();
                gridListRoom.DataSource = iphuthu.GetAllPhuThuDichVuByMaPhieuDat(Phieudkdto.MaPhieu, Phieudkdto.MaPhong.MaPhong);

                
            }
           //txtMaPhong.Text= checkoutmain.phieudkdto.MaPhong.MaPhong;


            ITienTe itiente = new TienTeDAL();
            //  cmbNgoaiTe.Properties. = itiente.GetAllTienTe();
            comNgoaiTe.DataSource = itiente.GetAllTienTe();
            comNgoaiTe.DisplayMember = "TenDonVi";
            comNgoaiTe.ValueMember = "MaDonVi";

        }

        private void labelControl8_Click(object sender, EventArgs e)
        {

        }

        private void txtMaKhachHang_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void txtPassport_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //Rool Back HÓa Đơn
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Bạn có thực sự muốn hủy thao tác này ko!", "Chú ý", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                //if ()
                //{
                //    MessageBox.Show("Thực Hiện Thành Công");
                //  //  LoadDataGrid();
                //}
                //else
                //    MessageBox.Show("Thực Hiện Không Thành Công", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);


                PhongDTO phongdto = Phieudkdto.MaPhong;
                ITinhTrangPhong itinhtrang = new TinhTrangPhongDAL();
                phongdto.TinhTrang = itinhtrang.GetTinhTrangPhongByID("3");

                IPhong iphong = new PhongDAL();
                iphong.UpdatePhong(phongdto);

                IPhieuDangKy iphieudk = new PhieuDangKyDAL();
                PhieuDangKyPhongDTO phieudk = Phieudkdto;
                phieudk.TinhTrang = false;
               // phieudk.NgayTra = DateTime.Now;

                iphieudk.UpdatePhieuDK(phieudk);

                IPhuThuDichVu iphuthu = new PhuThuDichVuDAL();


                PhuThuDichVuDTO phuthudto = iphuthu.GetPhuThuDichVuByID(iphuthu.GetMaxMaPhieuPhuThu() - 1);

                iphuthu.DeletePhuThuDichVu(phuthudto);

                this.Close();

            }
        }

        private void butChonKH_Click(object sender, EventArgs e)
        {
            Frm_LoadListCustomer listRoom = new Frm_LoadListCustomer();
            //listRoom.MyGetData = new Frm_LoadListCustomer.GetString(GetValue2);
            listRoom.ShowDialog();
        }


        public void GetValue2(String MaKH)
        {
            KhachHangDTO khdto = new KhachHangDTO();
            IKhachHang ikhach = new KhachHangDAL();
            khdto = ikhach.GetKhachHangByID(MaKH);
            txtMaKHHD.Text = khdto.MaKH;
            txtTenKHHD.Text = khdto.TenKH;
            txtDiaChiHD.Text = khdto.DiaChi;
            txtDienThoaiHD.Text = khdto.DienThoai;
            txtGhiChuHD.Text = khdto.GhiChu;


        }

        private void butHieuChinh_Click(object sender, EventArgs e)
        {
            IKhachHang ikhach = new KhachHangDAL();


        }

        private void butInHoaDon_Click(object sender, EventArgs e)
        {
            //IHoaDonTraPhong ihoadon = new HoaDonTraPhongDAL();
            //HoaDonTraPhongDTO hoadondto = ihoadon.GetHoaDonTraPhongByMaDangKy(Phieudkdto);
            //RP_HoaDonTraPhong rphoadon = new RP_HoaDonTraPhong(hoadondto);
            //IPhuThuDichVu iphuthu = new PhuThuDichVuDAL();

            //rphoadon.DataSource = iphuthu.ReportHoaDonDichVu(Phieudkdto.MaPhieu, Phieudkdto.MaPhong.MaPhong);
            //rphoadon.BindData();

            //rphoadon.ShowPreview();


        }

        private void inHóaĐơnTổngHợpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //IHoaDonTraPhong ihoadon = new HoaDonTraPhongDAL();
            //HoaDonTraPhongDTO hoadondto = ihoadon.GetHoaDonTraPhongByMaDangKy(Phieudkdto);
            //RP_HoaDonTraPhong rphoadon = new RP_HoaDonTraPhong(hoadondto);
            //IPhuThuDichVu iphuthu = new PhuThuDichVuDAL();

            //rphoadon.DataSource = iphuthu.ReportHoaDonDichVu(Phieudkdto.MaPhieu, Phieudkdto.MaPhong.MaPhong);
            //rphoadon.BindData();

            //rphoadon.ShowPreview();
        }

        private void inHóaĐơnChiTiếtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IHoaDonTraPhong ihoadon = new HoaDonTraPhongDAL();
            HoaDonTraPhongDTO hoadondto = ihoadon.GetHoaDonTraPhongByMaDangKy(Phieudkdto);
            RP_HoaDonTraPhong_ChiTiet rphoadonchitiet = new RP_HoaDonTraPhong_ChiTiet(hoadondto);
            IPhuThuDichVu iphuthu = new PhuThuDichVuDAL();

            IChiTietPhuThuDichVu ichitietphuthu = new ChiTietPhuThuDichVuDAL();

            rphoadonchitiet.DataSource = ichitietphuthu.GetListPhuThuDichVuByMaPhieuDangKy(Phieudkdto);
            rphoadonchitiet.BindData();

            rphoadonchitiet.ShowPreview();
        }

    }
}